package com.bcx.crm.service.docTemplateService;

import com.bcx.crm.entity.Template;
import com.bcx.crm.mapper.docTemplateMapper.SelectDocTemplateMapper;
import com.bcx.crm.plat.core.utils.SpringContextHolder;
import com.bcx.crm.plat.core.utils.StringUtils;
import com.bcx.crm.plat.util.UtilTool;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ys on 2018/4/3.
 */
@Service
public class SelectDocTemplateServiceImpl implements SelectDocTemplateService {

    private static final String TEMPLATE_NAME = "templateName";
    private static final String TEMPLATE_NAME_PINYIN = "templateNamePinyin";

//    @Cacheable("getListTemplate")   //标注该方法查询的结果注入缓存,再次访问直接读取缓存中的数据
    @Override
    public List<Template> getListTemplate(String result) {
        long currentTimeMillis = System.currentTimeMillis();
//        Map<String, Object> map = new HashMap<>();
        Map map = UtilTool.jsonToObj(result, Map.class);
        if (null != map){
            String templateName =(String) map.get(TEMPLATE_NAME);
            boolean allLetter = StringUtils.isAllLetter(templateName);
            if (allLetter){
                map.remove(TEMPLATE_NAME);
                map.put(TEMPLATE_NAME_PINYIN,templateName);
            }
        }
        SelectDocTemplateMapper selectDocTemplateMapper = SpringContextHolder.getBean("selectDocTemplateMapper");
        List<Template> listTemplate = selectDocTemplateMapper.getListTemplate(map);
        long timeMillis = System.currentTimeMillis();
        System.err.println(timeMillis - currentTimeMillis);
        return listTemplate;
    }
}
